package ltd.bugs.cute.jwt.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;

import ltd.bugs.cute.common.util.PropertyUtil;

/**
 * 通过JWT封装类token的认证
 * 
 * @author zhengzhq
 *
 */
public class JWTUtils {

  private static Logger logger = LoggerFactory.getLogger(JWTUtils.class);

  private static final String secret = PropertyUtil.getDefaultConfig("cute.jwt.secret",
      String.class, "065491012a7e297d55872e2e2ceaf54d");
  public static Algorithm algorithm = null;
  public static final String issuer =
      PropertyUtil.getDefaultConfig("cute.jwt.issuer", String.class, "jdsoft.ltd");
  public static JWTVerifier verifier = null;

  static {
    try {
      algorithm = Algorithm.HMAC256(secret);
      verifier = JWT.require(algorithm).withIssuer(issuer).build();
    } catch (Exception e) {
      logger.error("init jwt algorithm fail", e);
    }
  }
}
